﻿Partial Public Class Main

    Private Sub OSMemory_Paging()

        Available_MBytes()
        Pages_Input_sec()
        Pages_sec()
        Paging_File_Usage()
        Paging_File_Usage_Peak()
        Free_PTEs()

    End Sub

    Private Sub Available_MBytes()
        CalculateCounter("Available MBytes",
                         "Memory",
                         Me.txtAvMBmin,
                         Me.txtAvMBMax,
                         Me.txtAvMBavg,
                         Me.SparklineAvailableMbytes)

        'Color text for warning....
        If CDbl(Me.txtAvMBavg.Text) <= 100 Then
            Me.txtAvMBavg.BackColor = Color.Red
        ElseIf CDbl(Me.txtAvMBavg.Text) <= 200 Then
            Me.txtAvMBavg.BackColor = Color.Orange
        Else : Me.txtAvMBavg.BackColor = Color.LawnGreen
        End If
        If CDbl(Me.txtAvMBMax.Text) <= 100 Then
            Me.txtAvMBMax.BackColor = Color.Red
        ElseIf CDbl(Me.txtAvMBMax.Text) <= 200 Then
            Me.txtAvMBMax.BackColor = Color.Orange
        Else : Me.txtAvMBMax.BackColor = Color.LawnGreen
        End If
        If CDbl(Me.txtAvMBmin.Text) <= 100 Then
            Me.txtAvMBmin.BackColor = Color.Red
        ElseIf CDbl(Me.txtAvMBmin.Text) <= 200 Then
            Me.txtAvMBmin.BackColor = Color.Orange
        Else : Me.txtAvMBmin.BackColor = Color.LawnGreen
        End If

    End Sub

    Private Sub Pages_Input_sec()
        CalculateCounter("Pages Input/sec",
                         "Memory",
                         Me.txtPISmin,
                         Me.txtPISmax,
                         Me.txtPISavg,
                         Me.SparklinePagesInputSec)

        'Color text for warning....
        If CDbl(Me.txtPISavg.Text) > 10 Then
            Me.txtPISavg.BackColor = Color.Red
        Else : Me.txtPISavg.BackColor = Color.LawnGreen
        End If
        If CDbl(Me.txtPISmax.Text) > 10 Then
            Me.txtPISmax.BackColor = Color.Red
        Else : Me.txtPISmax.BackColor = Color.LawnGreen
        End If
        If CDbl(Me.txtPISmin.Text) > 10 Then
            Me.txtPISmin.BackColor = Color.Red
        Else : Me.txtPISmin.BackColor = Color.LawnGreen
        End If

    End Sub

    Private Sub Pages_sec()

        CalculateCounter("Pages/sec",
                         "Memory",
                         Me.txtPSmin,
                         Me.txtPSmax,
                         Me.txtPSavg,
                         Me.SparklinePagesSec)

        'Color text for warning....
        If CDbl(Me.txtPSavg.Text) > 10 Then
            Me.txtPSavg.BackColor = Color.Red
        Else : Me.txtPSavg.BackColor = Color.LawnGreen
        End If
        If CDbl(Me.txtPSmax.Text) > 10 Then
            Me.txtPSmax.BackColor = Color.Red
        Else : Me.txtPSmax.BackColor = Color.LawnGreen
        End If
        If CDbl(Me.txtPSmin.Text) > 10 Then
            Me.txtPSmin.BackColor = Color.Red
        Else : Me.txtPSmin.BackColor = Color.LawnGreen
        End If

    End Sub

    Private Sub Paging_File_Usage()

        CalculateCounter("% Usage",
                         "Paging File",
                         Me.txtPFUmin,
                         Me.txtPFUmax,
                         Me.txtPFUavg,
                         Me.SparklinePageFileUsage,
                         "_Total")

        'Color text for warning....
        If Not txtPFUavg.Text = "" Or Not txtPFUavg.Text = String.Empty Then
            If CDbl(txtPFUavg.Text) > 70 Then
                Me.txtPFUavg.BackColor = Color.Red
            Else : Me.txtPFUavg.BackColor = Color.LawnGreen
            End If
            If CDbl(txtPFUmax.Text) > 70 Then
                Me.txtPFUmax.BackColor = Color.Red
            Else : Me.txtPFUmax.BackColor = Color.LawnGreen
            End If
            If CDbl(txtPFUmin.Text) > 70 Then
                Me.txtPFUmin.BackColor = Color.Red
            Else : Me.txtPFUmin.BackColor = Color.LawnGreen
            End If
        End If
    End Sub

    Private Sub Paging_File_Usage_Peak()

        CalculateCounter("% Usage Peak",
                         "Paging File",
                         Me.txtPFUPmin,
                         Me.txtPFUPmax,
                         Me.txtPFUPavg,
                         Me.SparklinePageFileUsagePeak,
                         "_Total")
       
        'Color text for warning....
        If Not txtPFUPavg.Text = "" Or Not txtPFUPavg.Text = String.Empty Then
            If CDbl(txtPFUPavg.Text) > 70 Then
                Me.txtPFUPavg.BackColor = Color.Red
            Else : Me.txtPFUPavg.BackColor = Color.LawnGreen
            End If
            If CDbl(txtPFUPavg.Text) > 70 Then
                Me.txtPFUPmax.BackColor = Color.Red
            Else : Me.txtPFUPmax.BackColor = Color.LawnGreen
            End If
            If CDbl(txtPFUPavg.Text) > 70 Then
                Me.txtPFUPmin.BackColor = Color.Red
            Else : Me.txtPFUPmin.BackColor = Color.LawnGreen
            End If
        End If

    End Sub

    Private Sub Free_PTEs()

        CalculateCounter("Free System Page Table Entries",
                         "Memory",
                         Me.txtPTEmin,
                         Me.txtPTEmax,
                         Me.txtPTEavg,
                         Me.SparklinePTE)
       
        'Color text for warning....
        If CDbl(txtPTEavg.Text) < 10000 Then
            Me.txtPTEavg.BackColor = Color.Red
        Else : Me.txtPTEavg.BackColor = Color.LawnGreen
        End If
        If CDbl(txtPTEmax.Text) < 10000 Then
            Me.txtPTEmax.BackColor = Color.Red
        Else : Me.txtPTEmax.BackColor = Color.LawnGreen
        End If
        If CDbl(txtPTEmin.Text) < 10000 Then
            Me.txtPTEmin.BackColor = Color.Red
        Else : Me.txtPTEmin.BackColor = Color.LawnGreen
        End If

        
    End Sub

End Class
